<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div id="app">
	<div class="layout" id="classify_video">
		<div class="list" id="wrapper"
			style="overflow: hidden; margin-top: ${17-(4-amount)*3}em; padding-top: 0em;">
			<div class="program program-list">
				<div id="pullDown" class="" style="display: none;width:100%;margin:0;padding:0px;">
					<span class="pullDownIcon"></span><span class="pullDownLabel">往下拉刷新...</span>
				</div>
				<div id="filter_result" class="row row-content">
					<list-content v-for="(item,index) in content" :message="contextPath" :message2="resourcePath" 
						:item="item" :index="index">
					</list-content>
				</div>
				<div id="pullUp" class="" style="display: none;height:6em;">
					<span class="pullUpIcon"></span><span id="pullUpLabel" class="pullUpLabel">往上拉加载更多...</span>
				</div>
				<div id="emptyDiv" class="empty-div" style="display: none;">
					很遗憾，未找到你需要的节目</div>
			</div>
		</div>
	</div>
</div>

<script>
var params = {
		size:size,
		p_idx:1,
		orderby:options.options[0].value,
		category:options.options[1].value,
		region:options.options[2].value,
		year:options.options[3].value,
		bizCode:"${_context.bizCode}",
		siteCode:"${_context.siteCode}",
		categoryCode:"${_context.biz.categoryCode}"
};
var ts = null; 
var vm = new Vue({
	el:"#app",
	data:{
		content : [],
		templatePath : "${_templatePath}",
		resourcePath : "${_resourcePath}",
		contextPath : "${_contextPath}",
	},
	mounted:function() {
		this.$nextTick(function () {
			this.initScroll();
			this.lazyload();
	 	});
	},
	methods:{
		initScroll:function(){
			ts = new TouchScoller(IScollerConfig, getData);
			ts.init();
			ts.pageCount = 999;
			var pageIndex = getPageIndex("${param.efid}");
			if(pageIndex > ts.currentPage){
				ts.currentPage = parseInt(pageIndex); 
				ts.firstPage = ts.currentPage;
			}
			ts.load();
			ts.newRefresh();
		},
		lazyload:lazyload,
		gotoLink:gotoLink
	}
});
function lazyload(){
	$(document).ready(function(){
		$(".lazyImg").lazyload({ 
	        placeholder : "images/暂无图片.jpg", 
	        effect : "fadeIn" 
   			}); 
	});
}
function getData(pageIndex){
	//标记是否是重新筛选
	var reChoose = false;
	if(arguments.length == 0){
		ts.currentPage = 1;
		ts.firstPage = 1;
		var pageIndex = 1;
		reChoose = true;
	}
	params.p_idx = pageIndex;
	params.type = type;
	//xxxx年之前(页面初始化,year的值为xxxx年之前)
	var year = params.year; 
	if(year.indexOf("之前") != -1){
		params.year = year.substring(0,year.indexOf("之前"));
		params.early = true;
	}
	$.ajax({
		method:"get",
		//url:"/epg/api/categoryItemProxy/series/${_context.biz.categoryCode}.json?size=6&pageindex="+pageIndex+"&bizCode=${_context.bizCode}&siteCode=${_context.siteCode}",
		url:"${_contextPath}/api/search/filter.json",
		async:false,
		dataType: "json",
		data:params,
		success:function(data){
			//console.log(typeof data);
			var result = data;
			var add = result.resultSet;
			//console.log("series");
			//console.log(add);
			if(add&&add.length>0){
				//为新增数据增加页数属性pIdx
				for(var i=0;i<add.length;i++){
					add[i].pIdx = pageIndex;
				}
				//增加内容
				if(reChoose){
					vm.content = add;
					ts.fromStart();
				}else if(pageIndex == ts.currentPage){
					vm.content = vm.content.concat(add);
				}else{
					vm.content = add.concat(vm.content);
				}
				//保证可以一直滑
				ts.pageCount = ts.currentPage + 1;
				//刷新滚动条
				setTimeout(function(){ts.refershDiv();},500);
				//提示是否还有更多
				if(params.size == add.length){
					ts.showUpMore();
				}else{
					//显示没有更多内容
					ts.pageCount = ts.currentPage;
					ts.hideNoMore();
				}
			}else{
				//没有内容的两种情况
				if(reChoose){
					//显示搜索结果为空
					ts.newRefresh(0);
				}else{
					//当前是第一页，表示没有内容
					if(ts.currentPage == 1){
						//显示结果为空
						ts.newRefresh(0);
					}else{
						//显示没有更多内容
						ts.pageCount = ts.currentPage;
						ts.hideNoMore();
					}
				}
			}
		},
		error:function(XMLHttpRequest, textStatus, errorThrown){
			$("#loadingToast").hide();
		}
	});
}
function chooseOption(name,id,value){
	vm.content = [];
	options.chooseOption(name,id,value);
	params.orderby = options.options[0].value;
	params.category = options.options[1].value;
	params.region = options.options[2].value;
	params.year = options.options[3].value;
	ts.hideEmpty();
	getData();
	lazyload();
}
function init(){
	setTimeout(function(){
		var row = getRowNum("${param.efid}");
		ts.fromStart(row-1,180);
	},100);
}
</script>